<?php
include '../mysqladmin.php';
$strName = $_POST["username"];
$strPassword = $_POST["password"];
$strAct = $_POST["act"];
$sql1 = "SELECT * FROM admin WHERE account='{$strName}'";
$okk = mysqli_query($link, $sql1);
if($okk->num_rows){
    $code["msg"] = "用户名已存在！";
    $res = json_encode($code);
    echo $res;
    return;
}
$sql2 = "SELECT * FROM `actions` WHERE `action`='{$strAct}'";
$sql3 = "SELECT * FROM `admin` WHERE `action`='{$strAct}'";
$okk2 = mysqli_query($link, $sql2);
$okk3 = mysqli_query($link, $sql3);
if(!$okk2->num_rows || $okk3->num_rows>3){
//    如果激活码使用查过三次且激活码不存在
    $code["msg"] = "无效激活吗！";
    $res = json_encode($code);
    echo $res;
    return;
}

    $sql="insert into admin (account,password,`action` ) values ('{$strName}','{$strPassword}','{$strAct}') ";
    $result = mysqli_query($link, $sql);
    if($result){
        $code["status"] = true;
        $code["msg"] = "注册成功";
        $res = json_encode($code);
        echo $res;
    }else{
        $code["msg"] = $link->error;
        $res = json_encode($code);
        echo $res;
    }


mysqli_close($link);
?>
